package com.yklx.youke.admin.mapper;

import com.yklx.youke.entity.Course;
import org.apache.ibatis.annotations.*;
import java.util.List;

@org.apache.ibatis.annotations.Mapper
public interface CourseMapper {
    /**
     * 获取所有课程
     * @return 所有课程列表
     */
    @Select("SELECT * FROM courses ORDER BY created_at DESC")
    List<Course> getAllCourses();

    /**
     * 根据ID获取课程
     * @param courseId 课程ID
     * @return 课程对象
     */
    @Select("SELECT * FROM courses WHERE course_id = #{courseId}")
    Course getCourseById(@Param("courseId") String courseId);

    /**
     * 插入新课程
     * @param course 课程对象
     * @return 影响的行数
     */
    @Insert("INSERT INTO courses (course_id, course_name, course_description, teacher_id, subject, " +
            "grade_level, duration, price, max_students, status) " +
            "VALUES (#{courseId}, #{courseName}, #{courseDescription}, #{teacherId}, #{subject}, " +
            "#{gradeLevel}, #{duration}, #{price}, #{maxStudents}, #{status})")
    int insertCourse(Course course);

    /**
     * 更新课程
     * @param course 课程对象
     * @return 影响的行数
     */
    @Update("UPDATE courses SET course_name=#{courseName}, course_description=#{courseDescription}, " +
            "teacher_id=#{teacherId}, subject=#{subject}, grade_level=#{gradeLevel}, " +
            "duration=#{duration}, price=#{price}, max_students=#{maxStudents}, status=#{status} " +
            "WHERE course_id=#{courseId}")
    int updateCourse(Course course);

    /**
     * 删除课程
     * @param courseId 课程ID
     * @return 影响的行数
     */
    @Delete("DELETE FROM courses WHERE course_id = #{courseId}")
    int deleteCourse(@Param("courseId") String courseId);
}